import React from 'react'
import './Main.js'
import './ten/Main.js'

class AppEgret extends React.Component {
  constructor(props) {
    super(props)
    const {battleData, gameInfo} = this.props
    window.battleData = battleData
    window.gameInfo = gameInfo
    const roomDescribe = JSON.parse(battleData.room.roomDescribe)
    const entryCn = (roomDescribe.maxPlayerCount === 6 || roomDescribe.maxPlayerCount === -1) ? 'Niuniu' : 'Tenniu'
    this.state = {
      entryCn
    }
  }

  componentDidMount() {
    window.isMiniProgram = this.props.isMiniProgram
    /**
     * {
     * "renderMode":, //引擎渲染模式，"canvas" 或者 "webgl"
     * "audioType": "" //使用的音频类型，0:默认，1:qq audio，2:web audio，3:audio
     * "antialias": //WebGL模式下是否开启抗锯齿，true:开启，false:关闭，默认为false
     * }
     **/
    egret.runEgret({
      renderMode: 'canvas',
      audioType: 0
    })
  }

  render() {
    const { battleData, gameInfo } = this.props
    console.log(battleData, gameInfo) 
    return <div className="egret-player"
      data-entry-class={this.state.entryCn} data-orientation="auto" data-scale-mode="exactFit"
      data-resolution-mode="retina" data-frame-rate="30" data-content-width={gameInfo.width} data-content-height={gameInfo.height}
      data-show-paint-rect="false" data-show-fps="false" data-show-log="false"
      data-show-fps-style="x:0,y:0,size:12,textColor:0xffffff,bgAlpha:0.9">
    </div>
  }
}

export default AppEgret